<?php
namespace app\common\model;

class ShopGoodsDataModel extends BaseModel
{
    protected $name = 'shop_goods_data'; //定义栏目表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改
    /*读取器*/

    public function getBaseExtendAttr($value, $data)
    {
        if(empty($value)){
            return [];
        }
        return json_decode($value,true);
    }


    /*修改器*/
    protected function setBaseExtendAttr($value, $data)
    {
        $item = [];
        if ($value) {
            $value = trim($value);
            $list = explode("\r\n", $value);
            foreach($list as $v){
                $v = trim($v);
                if(!empty($v)){
                    $v = str_replace('：',":",$v);
                    $arr = explode(':',$v);
                    $arrKey = trim($arr[0]);
                    $arrValue = trim($arr[1]);
                    $item[$arrKey] = $arrValue;
                }
            }
        }
        return json_encode($item,JSON_UNESCAPED_UNICODE);
    }

    protected function getContentAttr($value)
    {
        return stripslashes(htmlspecialchars_decode($value));
    }
}
